<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>
        layui在线调试
    </title>
    <link rel="stylesheet" href="../../layuiadmin/layui-v2.5.5/layui/css/layui.css" media="all" type="text/css">
    <style type="text/css">
        body{margin: 10px;}
        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
        .input{height:35px;width:110px}
        .ss{
               position: absolute;
               left: 500px;
               top: 10px;
               z-index:111111;
           }
        .sw{
            position: absolute;
            left: 910px;
            top: 10px;
            z-index:111111;
        }
    </style>
</head>
<body bgcolor="white">
<div class="layui-form" id="form">
    <div class="demoTable">
        <i class="layui-icon"></i>
        <div class="layui-inline">
            <input name="name" style="width: 150px;" width="200" class="layui-input input" id="teamName" placeholder="请输入团队名称" autocomplete="off">
        </div>
        <div class="layui-inline">
            <input name="name" class="layui-input input" style="width: 150px;" id="teamPrincipal" placeholder="请输入团队负责人" autocomplete="off">
        </div>
           <div class="layui-inline">
                    <input name="name" class="layui-input input" style="width: 150px;" id="teamMember" placeholder="请输入团队成员" autocomplete="off">
                </div>
               <div class="button1 ss">
                        <button class=" layui-btn" data-type="reload">
                            <i class="layui-icon layui-icon-search" style="font-size: 15px; color: #F2F2F2;"></i>
                        </button>
                    </div>
        <table class="layui-hide" id="demo" lay-filter="test"></table><script type="text/html" id="barDemo">
    </script>
        </div>
    <script src="../../layuiadmin/layui-v2.5.5/layui/layui.js" type="text/javascript">
    </script> <script type="text/javascript" src="../../layuiadmin/lib/jquery.min.js">
    </script> <script type="text/javascript">
            var parentData = "";
        //格式转换
        function createrFormat(o){
            return o;
        }
        layui.config({
            version: '1554901097999' //为了更新 js 缓存，可忽略
        });
        layui.use(['form','jquery','laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider','layedit',], function(){
            $=layui.jquery;
            var laypage = layui.laypage //分页
                ,layer = layui.layer //弹层
                ,form = layui.form
                ,layedit=layui.layedit
                ,table = layui.table //表格
                ,carousel = layui.carousel //轮播
                ,element = layui.element //元素操作
                ,slider = layui.slider //滑块
                ,laydate = layui.laydate
            //执行一个 table 实例
            table.render({
                elem: '#demo'
                ,url: 'http://localhost:8080/HrEmp/team' //数据接口
                ,title: '用户表'
                ,width:1290
                ,limit:5
                ,method:'post'
                ,page: true //开启分页
                ,toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                ,totalRow: false //开启合计行
                ,cols: [[ //表头
                    {type:'checkbox',width:100,title:'全选', fixed: 'left'}
                    ,{field:'teamId', width:118, title: '序号'}
                    ,{field:'teamName', width:140, title: '团队名称', sort: true}
                    ,{field:'teamPrincipal',title: '团队负责人', width:140 }
                    ,{field:'teamMember',title:'团队成员',width:600 }
                    ,{field:'teamOperation',title:'团队操作',width:184 }
                ]],
                id:"listteam"
            });
            function getParentData(){
                // parentData 这是一个全局变量，当你点击按钮时给他付了值，子页面调用这个函数就能拿到这个值
                // 这只是返回一个字段，你可以返回一个对象
//                 	var parent ={}
//                 	parent.id = "1"
//                 		parent.name  = "10086"
//                 			parent.type = "10010"
//                 				parent.level = "1008611"

                return parentData;
            }
            //监听头工具栏事件
            table.on('toolbar(test)', function(obj){

                var checkStatus = table.checkStatus(obj.config.id)
                    ,data = checkStatus.data; //获取选中的数据
                var data = checkStatus.data;
                var str=[];
                if(data.length>0){
                    for(var i=0;i<data.length;i++){
                        str.push(data[i].teamId);
                    }
                }
                var arr=str.join(",");
                switch(obj.event){
                    case 'add':
                        index=layer.open({
                            type: 2,
                            title: '添加团队',
                            maxmin: true,
                            shadeClose: true, //点击遮罩关闭层
                            area : ['800px' , '520px'],
                            content: 'HrTeamadd.html',
                        });
                        layer.full(index);
                        break;
                    case 'update':
                        if(data.length === 0){
                            layer.msg('请选择一行');
                        } else if(data.length > 1){
                            layer.msg('只能同时编辑一个');
                        } else {
                            window.PartitionId=data;
                            index=layer.open({
                                type: 2,
                                title: '修改团队资料',
                                maxmin: true,
                                shadeClose: true, //点击遮罩关闭层
                                area : ['800px' , '520px'],
                                content: 'HrTeamupdate.html',
                            });
                            layer.full(index);
                        }
                        break;
                    case 'delete':
                        if(data.length === 0){
                            layer.msg('请选择一行');
                        } else {
                            layer.msg('删除');
                            $.ajax({
                                type:"POST",
                                url:"http://localhost:8080/HrEmp/teamdel",
                                datatype:"json",
                                data:{
                                    id:arr,
                                },
                                async:true,
                                success:function(data){
                                    layui.table.reload('listteam');
                                },error:function(){
                                    alert("失败")
                                }
                            })
                        }
                        break;
                };
            });

            //监听行工具事件
            table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    ,layEvent = obj.event; //获得 lay-event 对应的值
                parentData =data;
                if(layEvent === 'detail'){
                    window.PartitionId=data;
                    index=layer.open({
                        type: 2,
                        title: '查看',
                        maxmin: true,
                        skin: 'layui-layer-lan',
                        shadeClose: true, //点击遮罩关闭层
                        content: 'hremplist_list.html',
                    });
                    layer.full(index);
                }else if(layEvent=='workhistory'){
                    window.PartitionId=data;
                    index=layer.open({
                        type: 2,
                        title: '查看工作经历',
                        height:'100%',
                        width:'100%',
                        maxmin: true,
                        skin: 'layui-layer-lan',
                        shadeClose: true, //点击遮罩关闭层
                        area : ['1000px' , '600px'],
                        content: 'hrworkhistory.html',
                    });
                    layer.full(index);
                }else if(layEvent=='degree'){
                    window.PartitionId=data;
                                        index=layer.open({
                                            type: 2,
                                            title: '查看教育经历',
                                            maxmin: true,
                                            skin: 'layui-layer-lan',
                                            shadeClose: true, //点击遮罩关闭层
                                            area : ['1000px' , '600px'],
                                            content: 'hrdegree.html',
                                        });
                                        layer.full(index);
                }
            });
            //分页
            laypage.render({
                elem: 'listteam' //分页容器的id
                ,count: 100 //总页数
                ,skin: '#1E9FFF' //自定义选中色值
                //,skip: true //开启跳页
                ,jump: function(obj, first){
                    if(!first){
                        layer.msg('第'+ obj.curr +'页', {offset: 'b'});
                    }
                }
            });
            var $ = layui.$, active = {
                reload: function(){
                    //            var demoReload = $('#demoReload');
                    //            var department = $('#department');
                    //
                    //执行重载
                    table.reload('listteam', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        ,where: {
                            teamName:$('#teamName').val(),
                            teamPrincipal:$('#teamPrincipal').val(),
                            teamMember:$('#teamMember').val(),
                        }
                    });
                }
            };
            $(document).on("click",".layui-table-body table.layui-table tbody tr", function () {
                var index = $(this).attr('data-index');
                var tableBox = $(this).parents('.layui-table-box');
                //存在固定列
                if (tableBox.find(".layui-table-fixed.layui-table-fixed-l").length>0) {
                    tableDiv = tableBox.find(".layui-table-fixed.layui-table-fixed-l");
                } else {
                    tableDiv = tableBox.find(".layui-table-body.layui-table-main");
                }
                var checkCell = tableDiv.find("tr[data-index=" + index + "]").find("td div.laytable-cell-checkbox div.layui-form-checkbox I");
                if (checkCell.length>0) {
                    checkCell.click();
                }
            });

            $(document).on("click", "td div.laytable-cell-checkbox div.layui-form-checkbox", function (e) {
                e.stopPropagation();
            });

            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
    </div>
</div>
</body>
</html>